package cn.sunshuai.oenway;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.common.RemotingHelper;

public class Producer {
    public static void main(String[] args) throws Exception {
        //创建生产者组
        DefaultMQProducer producer = new DefaultMQProducer("oneway-producer-group");
        //设置nameserver地址
        producer.setNamesrvAddr("127.0.0.1:9876");
        //开启
        producer.start();
        //创建消息
        Message message = new Message("topic", "pet", "今天是个好日子".getBytes(RemotingHelper.DEFAULT_CHARSET));
        //发送消息
        producer.sendOneway(message);
        //关闭
        producer.shutdown();
    }

}
